package com.example.XqmZsb.dao;

import com.example.XqmZsb.domian.Dome01;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface DaoDemo extends JpaRepository<Dome01,Integer> {

/*

    @Query(value = "select * from dome01 where name = '张三'",nativeQuery = true)
    List<Dome01> SelectAll();

    @Query(value = "select * from dome01 where name = '李四'",nativeQuery = true)
    List<Dome01> SelectAll2();
*/
    @Query(value = "select * from dome01 where name = :name", nativeQuery = true)
    List<Dome01> findAllByName(String name);

    @Query(value = "select * from dome01 where name = :name or age = :age", nativeQuery = true)
    List<Dome01> findAllByNameAge(String name,Integer age);

    @Query(value = "select * from dome01 where :key = :value", nativeQuery = true)
    List<Dome01> findAllKey(String key,Object value);

    // 新增一个方法用于动态查询
    @Query(value = "select * from dome01 where (:key = 'name' and name = :value) or (:key = 'age' and age = :value)", nativeQuery = true)
    List<Dome01> findAllByKeyValue(String key, Object value);


}
